/**
 * 差旅统计信息业务逻辑处理接口实现类
 * @author zqd	差旅小组
 *
 * 上午10:09:51
 */
package com.cbts.service.show.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cbts.dao.DepartmentDao;
import com.cbts.dao.ReportDao;
import com.cbts.entity.CorporationMonthReport;
import com.cbts.entity.CorporationQuarterReport;
import com.cbts.entity.Department;
import com.cbts.entity.DepartmentMonthReport;
import com.cbts.entity.DepartmentQuarterReport;
import com.cbts.service.show.ReportService;
import com.cbts.util.Page;

public class ReportServiceImpl implements ReportService {
	protected ReportDao reportDao;
	protected DepartmentDao departmentDao;


	public void setReportDao(ReportDao reportDao) {
		this.reportDao = reportDao;
	}
	public void setDepartmentDao(DepartmentDao departmentDao) {
		this.departmentDao = departmentDao;
	}

	/* 
	 * @see com.cbts.service.show.ReportService#getCoMonthReport(java.lang.String)
	 */
	public List<CorporationMonthReport> getCoMonthReport(String year) {
		// zqd 上午11:17:18
		return reportDao.getReport(0, year, null, -1, -1).getPageItems();
	}

	/* 
	 * @see com.cbts.service.show.ReportService#getCoQuarterReport(java.lang.String)
	 */
	public List<CorporationQuarterReport> getCoQuarterReport(String year) {
		// zqd 上午11:17:18
		return reportDao.getReport(1, year, null, -1, -1).getPageItems();
	}

	/* 
	 * @see com.cbts.service.show.ReportService#getDeMonthReport(java.lang.String, java.lang.String)
	 */
	public List<DepartmentMonthReport> getDeMonthReport(String deid, String year) {
		// zqd 上午11:17:18
		return reportDao.getReport(0, year, deid, -1, -1).getPageItems();
	}

	/* 
	 * @see com.cbts.service.show.ReportService#getDeQuarterReport(java.lang.String, java.lang.String)
	 */
	public List<DepartmentQuarterReport> getDeQuarterReport(String deid,
			String year) {
		// zqd 上午11:17:18
		return reportDao.getReport(1, year, deid, -1, -1).getPageItems();
	}

	/* 
	 * @see com.cbts.service.show.ReportService#getYear(int, java.lang.String)
	 */
	public List<String> getYear(int type, String deid) {
		// zqd 上午09:36:56
		return reportDao.getYear(type, deid);
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.cbts.service.show.ReportService#finadAllDepMon(int, java.lang.String, int, int)
	 */
	public List<DepartmentMonthReport> finadAllDepMon(){
		return reportDao.finadAll(0, "", -1, -1).getPageItems();
	}
	/*
	 * (non-Javadoc)
	 * @see com.cbts.service.show.ReportService#finadAllDepQua(int, java.lang.String, int, int)
	 */
	public List<DepartmentQuarterReport> finadAllDepQua(){
		return reportDao.finadAll(1, "", -1, -1).getPageItems();
	}
	/*
	 * (non-Javadoc)
	 * @see com.cbts.service.show.ReportService#finadAllCorMon(int, java.lang.String, int, int)
	 */
	public List<CorporationMonthReport> finadAllCorMon(){
		return reportDao.finadAll(0, null, -1, -1).getPageItems();
	}
	/*
	 * (non-Javadoc)
	 * @see com.cbts.service.show.ReportService#finadAllCorQua(int, java.lang.String, int, int)
	 */
	public List<CorporationQuarterReport> finadAllCorQua(){
		return reportDao.finadAll(1, null, -1, -1).getPageItems();
	}
	
	/*
	 * @see com.cbts.service.show.ReportService#getDeSavecostingReport(java.lang.String)
	 */
	public Map<String,List<Double>> getDeSavecostingReport(String year){
		Map<String,List<Double>> map=new HashMap<String,List<Double>>();
		List<Department> dl=departmentDao.findAll().getPageItems();
		
		for(int i=0;i<dl.size();i++){
			String dname=dl.get(i).getDepartmentName();		//get department name
			List<DepartmentMonthReport> dmrl=reportDao.getReport(0, year, dl.get(i).getDepartmentId(), -1, -1).getPageItems();
			
			List<Double> list=new ArrayList<Double>();
			for(int j=0;j<12;j++)	list.add(0.0);			//初始化
			if(!dmrl.isEmpty()){							//该部门月报非空
				for(int j=0;j<dmrl.size();j++){				//循环月报list
					int index=Integer.parseInt(dmrl.get(j).getId().getMonths().split("-")[1])-1;
					list.set(index, dmrl.get(j).getSaveAmount());
				}
				map.put(dname, list);						//put in map
			}else{	//null
				map.put(dname, list);						//put in map
			}
		}
		return map;
	}

}
